INTRODUCTION TO DATABASES

INTRODUCTION TO DATABASES


Databases are a collection of data that is all related, and is used to organize, store and reaccess the data. Some important words related to data bases are:

Fields-A field is where each individual piece of information is put.

Record-A record is a group of fields.

Files-Records are then grouped together into files.

Index-An index is a list of records ordered according to their content.

Relational-Databases are relational, and are made up of related files. ex. students and tutors or customers and orders.)

Query-A query is a search function that lets you find information based on your search criteria.

Primary Key (PK)-The primary key is a unique field(s) that makes your record unique.

Foreign Key (FK)-The foreign key is the field that connects one record to another.

Entity Relationship Diagram-This is a diagram that shows the fields grouped into records and how they relate to each other.

Here is a simple example of a Entity Relationship Diagram:

jkjkhjkh.JPG
Rules Governing Relationships-Once you have created your entity relationship diagram it is required to include rules to govern the relationships.
For example a rule for the diagram above would be-A team can have many arena's such as a home and practice arena, but each arena can only have 1 home team.


NORMAL FORM

NORMAL FORM

Proper database design is dependant on 3 Normalization rules (Normal Forms) and must always obey them.

First Normal Form

No repeating columns of data or duplicate rows of data allowed. You can't put same types of data together!
nf1.JPG
1nfRJPAV.JPG
Here, we can see that in the second table we have 2 records in the same field, which violates the first normal form, and actually becomes confusing after further development of the database.
Back to Top

Second Normal Form

2020nfRJPAV.JPG

00002nfRJPAV.JPG

Each attribute must be dependent on the entire primary key. There must be full relevance to the primary key. In this example, we assume that a same song could be released by different artists and in different albums; and that all albums are unique. In the first (correct) table, we can see that all the fields are relevant to out primary composite key. You need to know and artist and album in order to find a certain version of the song and its unique length. In the second table, the album release date is only relevant to the album itself; you don't need to know the artist to know that date.
Back to Top

Third Normal Form

Each attribute is ONLY dependent to the primary key.
RJ_NF3a.JPG
RJ_NF3b.JPG

uyuyuyyyuyuyuyuyuy.JPG
This Breaks the third normal form because as seen in the example below we have said that one arena can only have one team. So the Arena Name can give you the team name, and thus everything is not only dependent on the primary key. To fix this you can create 4 Tables like those below, so that Team Name and Arena Name don't coincide. This fixes the problem so that it follows the third normal form.
Back to Top

jkjkhjkh.JPGrtadfs.JPG


RELATIONS & THEIR RESTRICTIONS

RELATIONS & THEIR RESTRICTIONS

There are 3 kinds of relations in the database. One to one, one to many, and many to many.
One to one is seen inside a table, one to many is seen between 2 tables, and many to many is seen among 3 or more tables. Now lets take a closer look at each of them...

One-to-One

Is seen inside one table. It is the relationship between the specific field of data and the primary key. eg "One building has only one address"
nf1i.JPG

One-to-Many

Is seen between two tables. It is the relationship when one value can unite (be common) for may others. eg "One school has many students but one student can be only in one school at the same time."
nf2i.JPG

Many-to-Many

Is seen among many tables. In this relationship, one value can have many of others, and those others can have many of this one. For example, "One student can have many classes, and one class can have many students." In this kind of relationship, you cannot directly relate two tables. There must be another table in between that would relate them. in our case, it should be something like Student Assignment, where the primary keys of those two tables will be foreign keys in the middle one.
nf3i.JPG
Back to Top
There are several restrictions in the database design and data entry...

- A primary key CAN NEVER contain a null value (it cannot to be empty). Every record must have a primary key in order to save its uniqueness.

- Other fields CAN be empty.

- And finally, plan your database before actually creating it, so you do not ecounter any difficulties or issues.

read this over again to make sure there are no confusions